package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.common.Result;
import com.amsp.oa.oademo.entity.EmployeeRegularization;
import com.amsp.oa.oademo.service.EmployeeRegularizationService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/employee-regularization")
@Api(tags = "员工转正申请接口")
public class EmployeeRegularizationController {

    @Autowired
    private EmployeeRegularizationService employeeRegularizationService;

    @PostMapping("/save")
    @ApiOperation("保存转正申请")
    public Result<Boolean> save(@RequestBody EmployeeRegularization employeeRegularization) {
        return Result.ok(employeeRegularizationService.saveOrUpdate(employeeRegularization));
    }

    @PostMapping("/batch-save")
    @ApiOperation("批量保存转正申请")
    public Result<Boolean> batchSave(@RequestBody List<EmployeeRegularization> records) {
        return Result.ok(employeeRegularizationService.saveOrUpdateBatch(records));
    }

    @GetMapping("/list")
    @ApiOperation("获取转正申请列表")
    public Result<IPage<EmployeeRegularization>> list(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String employeeId,
            @RequestParam(required = false) String department) {
        return Result.ok(employeeRegularizationService.getPage(current, size, name, employeeId, department));
    }

    @GetMapping("/{id}")
    @ApiOperation("获取转正申请详情")
    public Result<EmployeeRegularization> getById(@PathVariable Long id) {
        return Result.ok(employeeRegularizationService.getById(id));
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除转正申请")
    public Result<Boolean> delete(@PathVariable Long id) {
        return Result.ok(employeeRegularizationService.removeById(id));
    }
} 